/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.aionemu.loginserver.network.gameserver.clientpackets;

import com.aionemu.commons.database.dao.DAOManager;
import com.aionemu.commons.network.netty.packet.AbstractClientPacket;
import com.aionemu.loginserver.dao.AccountCharactersDAO;
import com.aionemu.loginserver.network.gameserver.GameServerChannelHandler;

/**
 * @author lyahim
 *
 */
public class CM_SET_CHARACTER_COUNT extends AbstractClientPacket<GameServerChannelHandler>
{
	int	count		= 0;
	int	accountId	= 0;

	public CM_SET_CHARACTER_COUNT(int opCode)
	{
		super(opCode);
	}

	@Override
	protected void readImpl()
	{
		accountId = readD();
		count = readC();
	}

	@Override
	protected void runImpl()
	{
		DAOManager.getDAO(AccountCharactersDAO.class).setCharacterCount(accountId, getChannelHandler().getGameServerInfo().getId(), count);
		getChannelHandler().getGameServerInfo().getAccountFromGameServer(accountId).setCharacterCount(getChannelHandler().getGameServerInfo().getId(), count);
	}
}
